﻿// AmiActionMessage.cs
// Copyright © 2013 Alex Forster

namespace Ami
{
	using System;
	using System.Diagnostics.Contracts;
	using Ami.ByteArrayExtensions;

	public sealed class AmiActionMessage: AmiMessage
	{
		private static readonly Random Rand = new Random();

		public AmiActionMessage( String action )
		{
			Contract.Assert( action != null );

			this["Action"] = action.Trim();

			var randBytes = new Byte[3];
			AmiActionMessage.Rand.NextBytes( randBytes );

			this["ActionID"] = 
				( (Int64)( DateTime.UtcNow.Subtract( new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc ) ) ).TotalMilliseconds ).ToString( "X" ) +
				";" + randBytes.ToHexString();
		}

		public String Action
		{
			get { return this["Action"]; }
		}

		public String ActionID
		{
			get { return this["ActionID"]; }
		}
	}
}
